package com.agent.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.agent.exception.MyException;
import com.agent.model.Agent;
import com.agent.model.AgentTravelAgency;
import com.agent.service.IAgentTravelAgencySer;

@Controller
@RequestMapping(value="/agentTravelAgency",produces="text/html;charset=UTF-8")
public class AgentTraveAgencyController extends BaseController{
	@Autowired
	IAgentTravelAgencySer agentTravelAgencySer;
	
	/**
	 * 领取公海旅行社
	 * @param model
	 * @param request
	 * @param agentTravelAgency
	 * @return
	 */
	@RequestMapping("/addAgentTravelAgency")
	@ResponseBody
	public String addAgentTravelAgency(Model model, HttpServletRequest request,
			AgentTravelAgency agentTravelAgency){
		try {
			Agent agent = (Agent) request.getSession().getAttribute("agent");
			agentTravelAgency.setAgentid(agent.getAgentid());
			int result = agentTravelAgencySer.addAgentTravelAgency(agentTravelAgency);
			return super.ajaxReturnTool.success(result).toJson();
		} catch (MyException e) {
			return super.ajaxReturnTool.fail(e.getCode()).toJson();
		}
	}
}
